package com.js.sys.adapter;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.js.lib_common.mvp.model.response.BindBean;
import com.js.sys.R;
import com.js.sys.greendao.db.BindingHistory;

import java.util.List;

/**
 * 扫码单adapter
 */
public class BindingHistoryAdapter extends BaseQuickAdapter<BindingHistory, BaseViewHolder> {

    private Context context;

    public BindingHistoryAdapter(Context context) {
        super(R.layout.item_bind_history);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolder helper, BindingHistory bean) {
      RecyclerView rcyList= helper.getView(R.id.rcy_history);
        BindingAdapter mAdapter = new BindingAdapter(context,null);
        GridLayoutManager mGridLayoutManager = new GridLayoutManager(context, 1);
        //方向，水平
        mGridLayoutManager.setOrientation(RecyclerView.VERTICAL);
        //给RecyclerView设置布局管理器
        rcyList.setLayoutManager(mGridLayoutManager);
        rcyList.setHasFixedSize(true);
        rcyList.setLayoutManager(mGridLayoutManager);
        rcyList.setAdapter(mAdapter);
        Gson gson=new Gson();
        List<BindBean> list =gson.fromJson(bean.getJson(), new TypeToken<List<BindBean>>() {}.getType());
        mAdapter.notShowDel();
        mAdapter.setNewData(list);
        helper.setText(R.id.tv_id,bean.getId()+"");
        helper.setText(R.id.tv_time,bean.getTime()+"");
        helper.setText(R.id.tv_upload,bean.getIsUpload()?"成功":"失败");
        helper.setText(R.id.tv_people,bean.getName()+"");
        helper.setText(R.id.tv_info,bean.getDes());
    }


}
